<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>在css样式中使用setup中的变量</title>
</head>

<body>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

    <div id="Application">
        <div class="box" :style="styleVar">
            简简单单的晚饭
        </div>
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                const height = Vue.ref(94)
                const whith = Vue.ref(200)
                const styleVar = Vue.computed(() => {
                    return {
                        '--box-width': whith.value + 'px',
                        '--box-height': height.value + 'px'
                    }
                })

                return {
                    styleVar
                };
            },
        });
        App.mount("#Application");
    </script>
    <style>
        .box {
            height: var(--box-height);
            width: var(--box-width);
            background: red;
        }
    </style>
</body>

</html>